package zhzz;

import java.util.ArrayList;
import java.util.List;

import zhzzofbl.bi2ofzh;
import zhzzofbl.bi3ofzh;
import zhzzofbl.bi4ofzh;
import zhzzofbl.bi5ofzh;
import bingliandshuju.BingLi3;
import bingliandshuju.BingLi4;
import bingliandshuju.BingLi5;
import bingliandshuju.SingleDataofAll;

import com.example.animaldoctor03.AllIllness;
import com.example.animaldoctor03.BingLi2;
import com.example.animaldoctor03.R;
import com.example.animaldoctor03.ZhuanJiaZD;

import commonClass.ADAQueryDiseaseIDAndDiseaseProbabilityByConditionsAction;
import commonClass.CopyOfADAQueryDiseaseIDAndDiseaseProbabilityByConditionsAction002;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import Modle.disease.ClinicalSymptomsKey;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class AllIllnessOfZH extends Activity {

	private SingleDataofzhzz singleDataofAllInessofzh = SingleDataofzhzz.getInstance();
/*	private ArrayList<Object> listofidofrequest = new ArrayList<Object>();
	private ArrayList<Object> listofidfromup = new ArrayList<Object>();*/
	private List<String> listofainessofzh2 = new ArrayList<String> ();
	private List<String> listofainessofzh = new ArrayList<String> ();
	private ArrayList<Object> listofceshi = new ArrayList<Object>();
	
	private String animalIDofAIN = "01371054603" ;
	private ArrayList<Object> resultListofAID = null;
	private ListView listofallness = null ;
	private void initElemofAI (){
		setContentView(R.layout.allillnessofzh);
		listofallness = (ListView)findViewById(R.id.listofjzzdofzh);
	}

	private void getshujuofAID(){
/*		Intent intentofAID = getIntent();
		Bundle bundleofAID = new Bundle();
		bundleofAID = intentofAID.getExtras();
		
		listofidfromup =  (ArrayList<Object>) bundleofAID.get("shuju");
		
		listofidofrequest = (ArrayList<Object>) singleDataofAllInessofzh.getListinformation();*/
		SingleDataofzhzz sinledataofzhzz = SingleDataofzhzz.getInstance();
		listofainessofzh = sinledataofzhzz.getidinformation();
		SingleDataofAll singledataofallofzh = SingleDataofAll.getInstance();
		listofainessofzh2 = singledataofallofzh.getidinformation();
		
	}
	private ArrayList<Object> assemblyofAID() {

		getshujuofAID();
		ArrayList<Object> list = new ArrayList<Object>();

		list.add(animalIDofAIN);
		list.add(listofainessofzh);
		list.add(listofainessofzh2);
		// Integer i = new Integer(10);
		// list.add(i);

		return list;
	}
	
	private void bindingofAID(final ArrayList<Object> list){
		
		try{
		final String[] resultofAID = new String[list.size()];
		// list.toArray(new String[list.size()]);
		for (int i = 0; i < list.size(); i++) {
			
			resultofAID[i] = ((ClinicalSymptomsKey)list.get(i)).getDiseaseName() ;  
		}
		int lengthofshuju ;
		if(resultofAID.length > 5){
			lengthofshuju = 5;
		}
		else{
			lengthofshuju = resultofAID.length;
		}
		
		final String xresultofAID [] = new String[lengthofshuju];
		for(int i = 0 ; i < lengthofshuju ; i ++){
			
			xresultofAID [i] = resultofAID[i];
		}
		ArrayAdapter<String> arrayAdapterofAID = new ArrayAdapter<String>(
				this, android.R.layout.simple_list_item_1, xresultofAID);
		listofallness.setAdapter(arrayAdapterofAID);
		listofallness.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				
				switch ( position ){
				
				case 0:
					Log.v("22222", ((ClinicalSymptomsKey)list.get(0)).getDiseaseName());
					Bundle bundleofILLN1 = new Bundle();
					bundleofILLN1.putSerializable("shuju", (ClinicalSymptomsKey) list.get(0));
					Intent intentofallillness1 = new Intent(AllIllnessOfZH.this , ZhuanJiaZDOfZH.class);
					intentofallillness1.putExtras(bundleofILLN1);
					startActivity(intentofallillness1);
					finish();
					break;
				case 1:
					//try{
					Bundle bundleofILLN2 = new Bundle();
					bundleofILLN2.putSerializable("shuju", (ClinicalSymptomsKey) list.get(1));
					Intent intentofallillness2 = new Intent(AllIllnessOfZH.this , bi2ofzh.class);
					intentofallillness2.putExtras(bundleofILLN2);
					startActivity(intentofallillness2);
					finish();
/*					}catch(RuntimeException e){
						builderofAINs.setMessage("不能使用该功能 ,请重试或者使用其他功能");
						builderofAINs.create().show();
					}*/
					break;
				case 2:
					//try{
					Bundle bundleofILLN3 = new Bundle();
					bundleofILLN3.putSerializable("shuju", (ClinicalSymptomsKey) list.get(2));
					Intent intentofallillness3 = new Intent(AllIllnessOfZH.this ,  bi3ofzh.class);
					intentofallillness3.putExtras(bundleofILLN3);
					startActivity(intentofallillness3);
					finish();
/*					}catch(RuntimeException e){
						builderofAINs.setMessage("不能使用该功能 ,请重试或者使用其他功能");
						builderofAINs.create().show();
					}*/
					break;
				case 3:
				//	try{
					Bundle bundleofILLN4 = new Bundle();
					bundleofILLN4.putSerializable("shuju", (ClinicalSymptomsKey) list.get(3));
					Intent intentofallillness4 = new Intent(AllIllnessOfZH.this ,  bi4ofzh.class);
					intentofallillness4.putExtras(bundleofILLN4);
					startActivity(intentofallillness4);
					finish();
/*					}catch(RuntimeException e){
						builderofAINs.setMessage("不能使用该功能 ,请重试或者使用其他功能");
						builderofAINs.create().show();
					}*/
					break;
				case 4:
					//try{
					Bundle bundleofILLN5 = new Bundle();
					bundleofILLN5.putSerializable("shuju", (ClinicalSymptomsKey) list.get(4));
					Intent intentofallillness5 = new Intent(AllIllnessOfZH.this ,  bi5ofzh.class);
					intentofallillness5.putExtras(bundleofILLN5);
					startActivity(intentofallillness5);
					finish();
/*					}catch(RuntimeException e){
						builderofAINs.setMessage("不能使用该功能 ,请重试或者使用其他功能");
						builderofAINs.create().show();
					}*/
					break;
				}
				
			}
			
			
			
		});
		}catch(NullPointerException e){
			android.app.AlertDialog.Builder builderofAIN = new AlertDialog.Builder(AllIllnessOfZH.this);
			builderofAIN.setMessage("无数据;请用其他功能");
			builderofAIN.create().show();
		}
		
	}
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		initElemofAI();
		
		ArrayList<Object> parasListofAID = assemblyofAID();
		final ArrayList<Object> resultListTofAID = null;
		CopyOfADAQueryDiseaseIDAndDiseaseProbabilityByConditionsAction002  iActionofBGZZ = new CopyOfADAQueryDiseaseIDAndDiseaseProbabilityByConditionsAction002();
		FunctionDispatcher functionDispacherofAID = new FunctionDispatcher();
		
		functionDispacherofAID.exceute(RemoteActionsName.QueryDiseaseIDAndDiseaseProbabilityByConditionsAction, parasListofAID, iActionofBGZZ, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				// TODO Auto-generated method stub
				try{
				AllIllnessOfZH.this.resultListofAID = resultList;
				bindingofAID(resultListofAID);
				}catch(NullPointerException e){
					android.app.AlertDialog.Builder builderofAINs = new AlertDialog.Builder(AllIllnessOfZH.this);
					builderofAINs.setMessage("无返回值 ,请使用其他功能");
					builderofAINs.create().show();
				}
			}
		} , this);


		
	}

}
